import {onMounted, reactive, watch} from "vue"
import http from "../utils/http"
import {ElMessageBox} from "element-plus"

export default () => {
  const state = reactive({
    loading: false,
    formRef: null,
  })

  const request = async (...args) => {
    state.loading = true
    const result = await http(...args)
    state.loading = false
    return result
  }

  const confirm = (message) => {
    return ElMessageBox.confirm(message, '提示', {
      type: 'warning'
    }).then(() => true).catch(() => false)
  }

  return {
    baseState: state,
    request,
    confirm,
  }
}
